﻿using System;

namespace Find01
{
    class Program
    {
        /// <summary>
        /// 输出100000以内的质数
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int numB = 2;
            Console.Write(2 + "     ");
            for (int i = 3; i < 100000; i++)
            {
                bool flagA = true;
                for (int j = 2; j < i; j++)
                {
                    if (i % j == 0)
                    {
                        flagA = false;
                        break;
                    }
                }
                if (flagA)
                {
                    numB++;
                    string strN = Convert.ToString(i);
                    //int lenG = 5-strN.Length;
                    string strM = strN.PadRight(5, ' ');
                    Console.Write(strM + " ");
                    if (numB % 15 == 0)
                    {
                        Console.WriteLine("");
                    }
                }
            }
            Console.WriteLine("100000内共有{0}个质数", numB);
            //第二种解法
             //取当前系统时间
            DateTime startTime = DateTime.Now;
            Console.WriteLine($"开始时间是{startTime}");
            Console.Write(2+"   ");
            int count = 1;
            for (int i = 3; i < 1001; i++)
            {
                bool isPrime = true;
                for (int j = 2; j < i; j++)
                {
                    if (i %j==0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime )
                {
                    Console.Write(i);

                    count++;
                }
            }
            Console.WriteLine($"1000以内共有{count}个质数");
        }
    }
}
